﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using PoolGame2.Controls;

namespace PoolGame2.Game
{
    public abstract class MoveableCamera : Camera
    {

        Vector3 minClip = new Vector3(-135, 65, -230);
        Vector3 maxClip = new Vector3(200, 150, 160);

        public MoveableCamera(PoolGame game)
            : base(game)
        {
        }

        public void translate(Vector3 translation)
        {
            Matrix cameraRotation = Matrix.CreateRotationX(updownRot) * Matrix.CreateRotationY(leftrightRot);
            Vector3 rotatedVector = Vector3.Transform(translation, cameraRotation);

            Vector3 tmpCameraPosition = cameraPosition + rotatedVector;
            if (IsXInBounds(tmpCameraPosition))
            {
                this.cameraPosition.X = tmpCameraPosition.X;
            }
            if (IsYInBounds(tmpCameraPosition))
            {
                this.cameraPosition.Y = tmpCameraPosition.Y;
            }
            if (IsZInBounds(tmpCameraPosition))
            {
                this.cameraPosition.Z = tmpCameraPosition.Z;
            }
            
        }

        public void rotate(Vector3 rotationAmount)
        {
            this.leftrightRot -= rotationAmount.X; 
            this.updownRot -= rotationAmount.Y;
        }

        private bool IsXInBounds(Vector3 pos)
        {
            return (pos.X >= minClip.X && pos.X <= maxClip.X);
        }
        private bool IsYInBounds(Vector3 pos)
        {
            return (pos.Y >= minClip.Y && pos.Y <= maxClip.Y);
        }
        private bool IsZInBounds(Vector3 pos)
        {
            return (pos.Z >= minClip.Z && pos.Z <= maxClip.Z);
        }
        
    }
}
